$(function () {
    console.log("bb");
    $.idcode.setCode();
    $("form").validate({
        rules: {
            uname: {
                required: true
            },
            upwd: {
                required: true
            }

        },
        messages: {
            uname: {
                required: "用户名必填"
            },
            upwd: {
                required: "密码必填"
            },
            yzm: {
                required: "验证码必填"
                // equalTo: "验证码不一致"
            }
        },      
        submitHandler: function () {
            var IsBy = $.idcode.validateCode();
            if (IsBy == true) {
                console.log(333);
                $.ajax({
                    url: "./api/login",
                    data: $("form").serialize(),
                    type: "post",
                    dataType: "json"
                }).then(function (res) {
                    console.log(res)
                    if (res.status == 101) {
                        //localStorage 最大能存储 5m,而已属于永久存储.
                        localStorage.setItem("currentUser", JSON.stringify(res.data));
    
                        layer.msg(res.msg);
    
                        window.location.href="magnifying.html";
                    }
                })

            }
            return false;
        }
    })
})